﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace WinFormUtilHelpV2
{
    public static class ListBoxToolV2
    {
        public static void ItemToolTip(this ListBox lsbox, ToolTip toolTip, MouseEventArgs e)
        {
            try
            {
                int _index = lsbox.IndexFromPoint(e.Location);
                if (_index != -1 && _index < lsbox.Items.Count)
                {
                    if (toolTip.GetToolTip(lsbox) != lsbox.Items[_index].ToString())
                    {
                        toolTip.IsBalloon = true;
                        toolTip.SetToolTip(lsbox, lsbox.Items[_index].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("ItemToolTip Exception:{0}", ex.Message.Trim()));
            }
        }
    }
}
